home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 5 / MACVOGL- / HDISP.C < prev    next >
C/C++ Source or Header  |  1992-07-19  |  2KB  |  134 lines

  1. #include <stdio.h>
  2.  
  3. #ifdef SGI
  4. #include <gl.h>
  5. #include <device.h>
  6. #else
  7. #include "vogl.h"
  8. #include "vodevice.h"
  9. #endif
  10.  
  11. extern int    getcharacter();
  12.  
  13. #define    XCOORD(x)    ((int)(x) - (int)'R')
  14. #define    YCOORD(y)    ((int)'R' - (int)(y))    /* invert as in tv coords */
  15.  
  16. /*
  17.  * newpage
  18.  *
  19.  *    draw up a new page with title, boxes, etc..
  20.  */
  21. newpage(fname, pageno)
  22.     char    *fname;
  23.     int    pageno;
  24. {
  25.     char    str[100];
  26.  
  27.     hcentertext(0);
  28.  
  29.     htextsize(0.05, 0.07);
  30.  
  31.     move2(-0.91, 0.9);
  32.     hcharstr("Hershey Character File: ");
  33.     hcharstr(fname);
  34.  
  35.     move2(0.45, 0.9);
  36.     sprintf(str, "Page No: %d", pageno);
  37.     hcharstr(str);
  38.  
  39.     htextsize(0.03, 0.03);
  40.  
  41.     hcentertext(1);
  42. }
  43.  
  44. /*
  45.  * display the hershey data set in the input file.
  46.  */
  47. main(ac, av)
  48.     int    ac;
  49.     char    **av;
  50. {
  51.     FILE    *fp;
  52.     int    charno, numpairs, page;
  53.     char    c, device[20], buf[1000], *p, str[100];
  54.     float    x, y, ox, oy;
  55.     short    val;
  56.  
  57.     if (ac < 2) {
  58.         fprintf(stderr, "hdisp: usage hdisp datafile\n");
  59.         exit(1);
  60.     }
  61.  
  62.     if ((fp = fopen(av[1], "r")) == NULL) {
  63.         fprintf(stderr, "hdisp: unable to open file %s\n", av[1]);
  64.         exit(1);
  65.     }
  66.  
  67.     hfont("times.r");
  68.  
  69.     winopen("hdisp");
  70.     qdevice(KEYBD);
  71.     ortho2(-1.0, 1.0, -1.0, 1.0);
  72.  
  73.     color(BLACK);
  74.     clear();
  75.  
  76.     ox = -0.8;
  77.     oy = 0.75;
  78.  
  79.     page = 1;
  80.  
  81.     color(WHITE);
  82.  
  83.     newpage(av[1], page);
  84.  
  85.     while (getcharacter(fp, &charno, &numpairs, buf)) {
  86.  
  87.         if (buf[2] != 0) {
  88.             p = &buf[2];        /* skip the width bytes */
  89.  
  90.             x = XCOORD(*p++) / 280.0;
  91.             y = YCOORD(*p++) / 280.0;
  92.             move2((Coord)(ox + x), (Coord)(oy + y));
  93.  
  94.             while (*p != 0) {
  95.                 if (*p == ' ') {
  96.                     p += 2;
  97.                     x = XCOORD(*p++) / 280.0;
  98.                     y = YCOORD(*p++) / 280.0;
  99.                     move2((Coord)(ox + x), (Coord)(oy + y));
  100.                 } else {
  101.                     x = XCOORD(*p++) / 280.0;
  102.                     y = YCOORD(*p++) / 280.0;
  103.                     draw2((Coord)(ox + x), (Coord)(oy + y));
  104.                 }
  105.             }
  106.         }
  107.  
  108.         move2((Coord)ox, (Coord)(oy - 0.11));
  109.         sprintf(str, "(%d)", charno);
  110.         hcharstr(str);
  111.  
  112.         ox += 0.22;
  113.         if (ox > 0.9) {
  114.             oy -= 0.22;
  115.             ox = -0.8;
  116.         }
  117.         if (oy < -0.9) {
  118.             oy = 0.75;
  119.             qread(&val);
  120.  
  121.             color(BLACK);
  122.             clear();
  123.  
  124.             color(WHITE);
  125.  
  126.             newpage(av[1], ++page);
  127.         }
  128.     }
  129.  
  130.     qread(&val);
  131.  
  132.     gexit();
  133. }
  134.